<style>
    .choice-list li {
        display: block;
    }
</style>
<div class="pop_up">
    <div class="pop_up_main">
        <div class="pop_up_tab">
            <div class="tab">
                <a href="#" class="on">基本设置</a>
            </div>
        </div>
        <div class="pop_up_box">
            <div class="pollBox" style="width:460px; margin-left:10px;">
                <div class="LogList">
                    <ul>
                        <li>
                            <div class="left alR" style="width: 15%;">
                                投票主题：
                            </div>
                            <div class="left" style="width: 83%;">
                                <input id="vote_title" name="title" type="text" class="in_put vote_param" style="width:68%" onblur="this.className='in_put vote_param'" onfocus="this.className='in_put2 vote_param'" maxlength="30"/><a class="ml5" id="tog_explain" href="javascript:void(0)">添加投票详细说明</a>
                            </div>
                            <div class="C">
                            </div>
                        </li>
                        <li id="vote_explain_button" style="display:none;">
                            <div class="left alR" style="width: 15%;">
                                详细说明：
                            </div>
                            <div class="left" style="width: 82%;">
                                <textarea id="vote_explain" name="explain" rows="5" class="Text vote_param" style="width:70%" onblur="this.className='in_put vote_param'" onfocus="this.className='in_put2 vote_param'"></textarea>
                            </div>
                            <div class="C">
                            </div>
                        </li>
                        <li>
                            <div class="lineB_D_D">
                            </div>
                        </li>
                        <!-- 选项 BEGIN -->
                        <li id="vote_default">
                            <div class="left alR" style="width: 15%;">
                                候选项1：
                            </div>
                            <div class="left" style="width: 82%;">
                                <input name="opt[]" type="text" class="in_put vote_opt" id="textfield3" style="width:70%" onblur="this.className='in_put vote_opt'" onfocus="this.className='in_put2 vote_opt'" maxlength="30"/>
                            </div>
                            <div class="C">
                            </div>
                        </li>
                        <li>
                            <div class="left alR" style="width: 15%;">
                                候选项2：
                            </div>
                            <div class="left" style="width: 82%;">
                                <input name="opt[]" type="text" class="in_put vote_opt" id="textfield3" style="width:70%" onblur="this.className='in_put vote_opt'" onfocus="this.className='in_put2 vote_opt'" maxlength="30"/>
                            </div>
                            <div class="C">
                            </div>
                        </li>
                        <li>
                            <div class="left alR" style="width: 15%;">
                                候选项3：
                            </div>
                            <div class="left" style="width: 82%;">
                                <input name="opt[]" type="text" class="in_put vote_opt" id="textfield3" style="width:70%" onblur="this.className='in_put vote_opt'" onfocus="this.className='in_put2 vote_opt'" maxlength="30"/>
                            </div>
                            <div class="C">
                            </div>
                        </li>
                        <li>
                            <div class="left alR" style="width: 15%;">
                                候选项4：
                            </div>
                            <div class="left" style="width: 82%;">
                                <input name="opt[]" type="text" class="in_put vote_opt" id="textfield3" style="width:70%" onblur="this.className='in_put vote_opt'" onfocus="this.className='in_put2 vote_opt'" maxlength="30"/>
                            </div>
                            <div class="C">
                            </div>
                        </li>
                        <li>
                            <div class="left alR" style="width: 15%;">
                                候选项5：
                            </div>
                            <div class="left" style="width: 82%;">
                                <input name="opt[]" type="text" class="in_put vote_opt" id="textfield3" style="width:70%" onblur="this.className='in_put vote_opt'" onfocus="this.className='in_put2 vote_opt'" maxlength="30"/>
                            </div>
                            <div class="C">
                            </div>
                        </li>
                        <li id="vote_more_options">
                            <div class="lineB_D_D">
                            </div>
                        </li>
                        <li>
                            <div class="left alR" style="width: 15%;">
                                &nbsp;
                            </div>
                            <div class="left" style="width: 82%;">
                                <a id="add_more" href="javascript:more()">增加更多候选项</a>
                            </div>
                            <div class="C">
                            </div>
                        </li>
                        <li>
                            <div class="left alR" style="width: 15%;">
                                可投选项：
                            </div>
                            <div class="left" style="width: 82%;">
                                <select id="vote_type" name="type" class="in_put_01 vote_param">
                                    <option value="0">单选</option>
                                    <option value="1">可多选，最多2项</option>
                                    <option value="2">可多选，最多3项</option>
                                    <option value="3">可多选，最多4项</option>
                                    <option value="4">可多选，最多5项</option>
                                </select>
                            </div>
                            <div class="C">
                            </div>
                        </li>
                        <li>
                            <div class="left alR" style="width: 15%;">
                                有效时间：
                            </div>
                            <div class="left" style="width: 82%;">
							<php>$now_year = date('Y',time());</php>
                                <input type="radio" class="deadline_type vote_param" name="deadline_type" id="deadline_type_7" value="7" checked="checked"/>一周 <input type="radio" class="deadline_type vote_param" name="deadline_type" id="deadline_type_30" value="30" />一个月 <input type="radio" class="deadline_type vote_param" name="deadline_type" id="deadline_type_u" value="u" />自定义 <!-- TODO 灰色 -->
                                <select name="year" id="vote_year" class="in_put_01 vote_param">
                                    <option value="{$now_year}">{$now_year}</option>
                                    <option value="<php>echo $now_year+1;</php>">
                                        <php>
                                            echo $now_year+1;
                                        </php>
                                    </option>
                                    <option value="<php>echo $now_year+2;</php>">
                                        <php>
                                            echo $now_year+2;
                                        </php>
                                    </option>
                                </select>
                                年
                                <select name="month" id="vote_month" class="in_put_01 vote_param">
                                    <php>
                                        $month = array(1,2,3,4,5,6,7,8,9,10,11,12);
                                    </php>
                                    <volist name="month" id="vo">
                                        <option value="{$vo}"
                                            <php>
                                                if($vo==$now_month){
                                            </php>selected="selected"
                                            <php>
                                                }
                                            </php>>{$vo}
                                        </option>
                                    </volist>
                                </select>
                                月
                                <select name="day" id="vote_day" class="in_put_01 vote_param">
                                    <php>
                                        $day = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30);
                                    </php>
                                    <volist name="day" id="vo" class="vote_param">
                                        <option value="{$vo}"
                                            <php>
                                                if($vo==$now_day){
                                            </php>selected="selected"
                                            <php>
                                                }
                                            </php>>{$vo}
                                        </option>
                                    </volist>
                                </select>
                                日
                            </div>
                            <div class="C">
                            </div>
                        </li>
                        <li>
                            <div class="left alR" style="width: 15%;">
                                是否匿名：
                            </div>
                            <div class="left" style="width: 82%;">
                                <input type="radio" class="is_anonymous vote_param" name="is_anonymous" value="0" checked="checked"/>否 <input type="radio" class="is_anonymous vote_param" name="is_anonymous" value="1"/>是 
                            </div>
                            <div class="C">
                            </div>
                        </li>
                        <eq name="type" value="1">
                            <li>
                                <div class="left alR" style="width: 15%;">
                                    &nbsp;
                                </div>
                                <div class="C">
                                </div>
                            </li>
                        </eq>
                    </ul>
                </div>
                <!-- LogList end  -->
            </div>
        </div>
    </div>
    <div id="preview" class="preview_r">
    </div>
</div>
<script>
                                        	var index= '{$index}';
                                        	var layout = '{$layout}';
                                        	var parentId = '{$parentId}';
                                        	var id = '{$id}';
                                        	var namespace = '{$_GET['tagName']}';
                                    		var postData = new Array();
    										var imageLimit = new Array();
    
                                $(function(){
                                    $("#tog_explain").toggle(function(){
                                        $("#vote_explain_button").show("slow");
                                        $(this).text("隐藏投票详细说明");
                                    }, function(){
                                        $("#vote_explain_button").hide("slow");
                                        $(this).text("添加投票详细说明");
                                    });
                                });
    							
    			var flag = 1;
    			var num_limit = 10;
    			
    			function check_vote(){
                    var title = $.trim($("#vote_title").val());
                    if (!title) {
                        alert("投票主题不能为空!");
                        return false;
                    }
                    flag = 0;
    				
                    $(".vote_opt").each(function(i){
                        if ($.trim($(this).val())) 
                            flag++;
                    })
                    if (flag < 2) {
                        alert("至少填写2个选项!");
                        return false;
                    }
                    var type = $('#vote_type').val();
                    if (type > flag - 1) {
                        alert('投票选项不得少于可选选项限数');
                        return false;
                    }
    				return true;
                }
                
                function more(){
                    var new_vote = $('#vote_default').clone();
                    if (flag == 1) {
                        $('.vote_opt').each(function(i){
                            flag++;
                        });
                    }
                    new_vote.children('.alR').html("候选项" + flag + "：");
                    new_vote.find('input').val('');
                    flag++;
                    $('#vote_more_options').before(new_vote);
                    // $("#more_options").show();
                    // $("#add_more").hide();
                    num_limit--;
                    if (num_limit == 0) {
                        $('#add_more').hide();
                        return;
                    }
                }
    							
                                  function preview(){
                                    var sendData = getPostData();
    								if(!sendData) return;
                                    $.ajax({
                                        type: "POST",
                                        url: APP + '&mod=Diy&act=previewModel',
                                        data: sendData,
                                        dataType: 'json',
                                        success: function(result){
                                           $('#preview').html(result.html);
                                            var content = '<div id="diy_copyHtmlContent">\
                                                		复制源代码:<input type="text" id="copyHtmlContent" onclick="select();" style="width:150px;" />\
                                            		</div>'
    										var widget = '<div id="diy_copyHtmlContent">\
                                                		复制标签:<input type="text" id="copyWidgetContent" onclick="select();" style="width:150px;" />\
                                            		</div>'		
                                            $('#preview').append(content);
    										$('#preview').append(widget);
                                            $('#diy_copyHtmlContent');
                                            $('#copyHtmlContent').val(result.html).bind('click',function(){
    											copyToClipboard(result.html);
    										});
    										$('#copyWidgetContent').val(result.widget).bind('click',function(){
    											copyToClipboard(result.widget);
    										});
    										//$('#copyHtml').click();
                                        }
                                    });
                                }
                                        	
                                        	function savemodel(){
                        						var sendData = getPostData();
    											if(!sendData) return;
                                    			$.ajax({
                                    				type : "POST",
                                    				url  : APP + '&mod=Diy&act=saveModel',
                                    				data : sendData,
                                    				dataType : 'json',
                                    				success : function(result){
                                     					//var jsonData = eval('('+result+')');
                                        		 		frameArray[parentId][layout][index] = result['sign'];
                                        		 		 if($('#'+id).html() == null){
                                    			  		 $('#placeholder').html(result['html']);
                                        		 		 $('#placeholder')
                                        		 			.removeAttr('class')
                                        					.removeAttr('style')
                                        					.addClass('mb10')
                                        					.attr('id',id)
                                        					.attr('rel',namespace)
                                        		 			.prepend('<div class="diy_edit"><div class="ico_edit"><a href="javascript:void(0)" onclick="updateDiyModel(\''+id+'\',\''+namespace+'\')" class="ico_diyedit" title="设置">设置</a> <a href="javascript:void(0)" class="ico_diydel" onclick="deleteDiy(\'' + id + '\')" title="删除">删除</a></div></div>');
                                		        		 }else{
                                		    			 	$('#'+id).html(result['html']);
                                		    				$('#'+id).prepend('<div class="diy_edit"><div class="ico_edit"><a href="javascript:void(0)" onclick="updateDiyModel(\''+id+'\',\''+namespace+'\')" class="ico_diyedit" title="设置">设置</a> <a href="javascript:void(0)" class="ico_diydel" onclick="deleteDiy(\'' + id + '\')" title="删除">删除</a></div></div>');
                                		    
                                		    			 }
                                    				}
                                    			});
                                        	}
                                            function getPostData(){
    											if(!check_vote()) return false;
    											var result = 'tagName=' + namespace;
    											$('.vote_opt').each(function(){
    												result += '&opt[]='+$(this).val();
    											});
    											$('.vote_param').each(function(){
    												if($(this).attr('type') == 'radio'){
    													if($(this).attr('checked')){
    														result += '&'+$(this).attr('name')+'='+$(this).val();
    													}
    												}else{
    													result += '&'+$(this).attr('name')+'='+$(this).val();
    												}
    											});
                                                return result;
                                            }
    
</script>
